feat(servicebus): add list_queue_sessions and list_subscription_sessions#46575
Open
EldertGrootenboer wants to merge 13 commits intoAzure:mainfrom
Open
feat(servicebus): add list_queue_sessions and list_subscription_sessions#46575EldertGrootenboer wants to merge 13 commits intoAzure:mainfrom
EldertGrootenboer wants to merge 13 commits intoAzure:mainfrom
Conversation
…lient (Azure#44999) - Pass **kwargs from __init__ to _build_pipeline() in both sync and async ServiceBusAdministrationClient so transport kwargs (connection_verify, transport, policies, ssl_context) reach the transport layer - Add unit tests verifying kwargs forwarding for both sync and async clients - Matches pattern from Azure#26015 fix for ServiceBusClient and azure-core base
- Add _SessionBrowser and _SessionBrowserAsync for management-only AMQP connections - Add create_mgmt_client to pyamqp and uamqp transports - Add create_mgmt_client_async to async pyamqp transport - Add list_queue_sessions/list_subscription_sessions to sync and async ServiceBusClient - Handle 404+SessionNotFound as empty result in list_sessions_op handler - Add live tests for queue sessions, subscription sessions, and updated_since mode
Contributor
There was a problem hiding this comment.
Pull request overview
This PR exposes the AMQP management com.microsoft:get-message-sessions operation in Track 2 by adding public ServiceBusClient APIs to list session IDs for session-enabled queues and subscriptions (sync + async), plus transport support and tests.
Changes:
- Added internal “management-only” session browser handlers (sync/async) and wired them into new
ServiceBusClient.list_queue_sessions()/list_subscription_sessions()APIs. - Added management-client factories for management-only AMQP clients in both pyamqp and uamqp transports (sync/async).
- Updated mgmt handlers + added tests (live tests for list sessions; unit regression tests for management client kwargs forwarding).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/servicebus/azure-servicebus/tests/test_mgmt_client_kwargs.py | Adds regression tests ensuring admin client __init__ kwargs are forwarded to _build_pipeline (sync/async). |
| sdk/servicebus/azure-servicebus/tests/test_list_sessions.py | Adds live tests for listing queue/subscription session IDs and updated-since mode. |
| sdk/servicebus/azure-servicebus/azure/servicebus/management/_management_client.py | Forwards **kwargs into _build_pipeline for sync admin client. |
| sdk/servicebus/azure-servicebus/azure/servicebus/aio/management/_management_client_async.py | Forwards **kwargs into _build_pipeline for async admin client. |
| sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py | Adds create_mgmt_client() factory for management-only pyamqp client. |
| sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_uamqp_transport.py | Adds create_mgmt_client() factory for management-only uamqp client. |
| sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py | Adds create_mgmt_client_async() for async management-only pyamqp client. |
| sdk/servicebus/azure-servicebus/azure/servicebus/_session_browser.py | New sync internal handler for management-only session listing. |
| sdk/servicebus/azure-servicebus/azure/servicebus/aio/_session_browser_async.py | New async internal handler for management-only session listing. |
| sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py | Adds public sync list_queue_sessions / list_subscription_sessions APIs. |
| sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py | Adds public async list_queue_sessions / list_subscription_sessions APIs. |
| sdk/servicebus/azure-servicebus/azure/servicebus/_common/mgmt_handlers.py | Adjusts list_sessions_op behavior to return empty list on 404. |
- mgmt_handlers.list_sessions_op: gate the empty-list 404 response on the com.microsoft:message-not-found condition so other 404s (entity not found, auth failures) propagate as errors instead of being silently swallowed. - _session_browser / _session_browser_async: normalize naive updated_since datetimes to UTC so the wire timestamp is independent of the host timezone (matches how naive datetimes are treated elsewhere in the SDK). - _session_browser / _session_browser_async: build _auth_uri from the full entity path (including /Subscriptions/<sub>) so SAS auth resolves correctly when listing subscription sessions. - _session_browser / _session_browser_async: remove unused imports (logging/_LOGGER, BaseHandler in async, Any/Union, _MAX_DATETIME, _amqp_timestamp_value). - _servicebus_client.list_queue_sessions / list_subscription_sessions: drop the forward-reference quotes around datetime so the import is actually used (matches the async client style). - tests/test_list_sessions.py: remove the unused _logger setup and its logging/get_logger imports.
Add 'timeout > 0' validation to ServiceBusClient.list_queue_sessions, list_subscription_sessions and their async counterparts. Matches the existing validation pattern used by sender/receiver/session operations across the SDK.
- Add 'pylint:disable=do-not-import-asyncio' on the asyncio import in _session_browser_async.py to match every other async module in this package.
- Use str keys ('last-updated-time', 'skip', 'top') in the get-message-sessions request body to match the dict[str, Any] signature of _mgmt_request_response_with_retry, fixing two new mypy errors. The pyamqp mgmt layer encodes string keys to bytes on the wire, so behavior is unchanged.
…ests - tests/test_list_sessions.py: add list_subscription_sessions empty + updated_since coverage so the topic/subscription entity path is exercised in both wire modes. - tests/async_tests/test_list_sessions_async.py: new module covering the _SessionBrowserAsync path (sync parity: queue + subscription, active / empty / updated_since).
All four updated_since live tests (sync + async, queue + subscription) now use 'datetime.now(timezone.utc) - timedelta(minutes=1)' as the boundary so client/server clock skew can't push the freshly-sent session past the cutoff and cause flakes.
Replace the legacy '# type:' return comment with explicit '-> List[str]' annotations on list_queue_sessions and list_subscription_sessions in both the sync and async ServiceBusClient. Matches other modern public APIs and surfaces the return type to type checkers and IDE tooling.
The previous docstring said 'sessions whose state was updated' which only matches the user-set state via SetState. The wire-level get-message-sessions operation actually returns sessions whose last update (state change OR message activity) is after the cutoff. Updated the docstrings on the four public methods and on the internal _SessionBrowser/_SessionBrowserAsync.list_sessions to reflect the actual behavior.
_SessionBrowserAsync calls self._amqp_transport.create_mgmt_client_async(...) but the uamqp async transport never exposed it, so list_queue_sessions / list_subscription_sessions on the async client would AttributeError when uamqp_transport=True. Added the factory mirroring the sync UamqpTransport.create_mgmt_client implementation.
d6be5e9 to
ce40401
Compare
- _pyamqp_transport.py: correct the create_mgmt_client docstring to reference azure.servicebus._common._configuration.Configuration (the configuration class lives in the _common subpackage; the previous path was wrong and broke Sphinx cross-references). - tests/test_list_sessions.py and tests/async_tests/test_list_sessions_async.py: reorder imports so stdlib (uuid, datetime) comes before third-party (pytest), matching pylint expectations and the rest of the test suite.
- _create_session_browser (sync + async): expand stub docstring with params, return, and rtype to satisfy docstring-missing-* checks. - create_mgmt_client / create_mgmt_client_async (4 transport variants): add docstring-keyword-should-match-keyword-only disable, mirroring the existing pattern on create_send_client where the keyword-only args are passed through **kwargs. - _transport/_uamqp_transport.py: hoist 'AMQPClient' to the module-level uamqp import block so create_mgmt_client doesn't trip used-before-assignment. - _transport/_pyamqp_transport.py: drop the redundant TYPE_CHECKING-only import of AMQPClient (already imported at module level for runtime use). - aio/_transport/_pyamqp_transport_async.py: import AMQPClientAsync directly from ..._pyamqp.aio (it's exported there) instead of the aliased _client_async import; remove the redundant TYPE_CHECKING import; use AMQPClientAsync uniformly. - aio/_servicebus_client_async.py: extend the existing client-method-missing-tracing-decorator disable to cover the -async variant (matches the sync-side disable already in this module).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.